package com.bxl.netty.rpc.register.server.service.impl;


import com.bxl.netty.rpc.client.common.client.ClientInfo;
import com.bxl.netty.rpc.common.message.BaseResponse;
import com.bxl.netty.rpc.common.message.PackageMsg;
import com.bxl.netty.rpc.common.message.RegisterContent;
import com.bxl.netty.rpc.register.server.RegisterServerContext;
import com.bxl.netty.rpc.register.server.SlidingWindow;
import com.bxl.netty.rpc.register.server.service.IOperService;

/**
 * <>
 *
 * @author baixl
 * @date 2021/3/5
 */
public class HeartBeatService implements IOperService {
    public Object deal(PackageMsg<RegisterContent> msg, RegisterServerContext context) {
        RegisterContent content = msg.getContent();
        ClientInfo clientInfo = new ClientInfo(content.getApp(),content.getIp(), content.getPort(), null);
        SlidingWindow slidingWindow = context.getSlidingWindow();
        System.out.println(clientInfo.getApp()+":"+clientInfo.getIp() + ":" + clientInfo.getPort() + " HeartBeat");
        slidingWindow.register(clientInfo);
        return BaseResponse.success();
    }
}
